const { validate } = require('./validate');
const { body } = require('express-validator');
const { getAccountInfoByUsername } = require('../model/account');

module.exports.regValidator = validate([
  body('username')
    .notEmpty()
    .custom(async (username) => {
      let accounts = await getAccountInfoByUsername(username);
      if (accounts.length !== 0) {
        return Promise.reject('Account exists.');
      }
    }),
  body('password').notEmpty(),
]);
